package controller;
import java.util.List;

import model.User;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import service.UserService;

@Controller
public class UserController {
	
	@Autowired
	private UserService userService;
	
	
	
	@RequestMapping("/selectUserById")
	public String  selectUserById(Model model,String  id)
	{
		User user=null;
		
		if(id!=null&&id!="")
		{
			
			try {
				user = userService.selectUserById(Integer.parseInt(id));
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			
		
		}
		model.addAttribute("user", user);
		return "selectUserById";
		
	}
	
	
	@RequestMapping("/selectUserByName")
	public String  selectUserByName(Model model,String  name)
	{
		List<User> list=null;
		
		if(name!=null&&name!="")
		{
			
			try {
				list = userService.selectUserByName(name);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			
		
		}
		model.addAttribute("list", list);
		return "selectUserByName";
		
	}
	
}
